package com.cfw.authority;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cfw.properties.CustomProperties;
import com.cfw.util.StringUtil;

/**
 * 접근권한 확인 클래스에서 사용할 Utility 클래스
 * </br><b>History</b><br/>
 * <pre>
 * 2012. 5. 11. 최초작성
 * </pre>
 * @author 박형일
 * @version 1.0
 */
public final class AuthorityUtil {
	private final static Logger logger = LoggerFactory.getLogger(AuthorityFilter.class);
	
	private AuthorityUtil() {
		// static class
	}
	/**
	 * 전달된 매개변수로 부터 접근권한대상ID를 추출하여 반환
	 * @param contextRoot
	 * @param uri
	 * @param query
	 * @return
	 */
	public static String getSid(final String contextRoot, final String uri, final String query) {
		final String result = uri.substring(uri.indexOf(contextRoot) + contextRoot.length());
		return result;
	}
	
	/**
	 * 전달된 매개변수로 부터 접근권한대상ID를 추출하여 반환
	 * @param contextRoot
	 * @param href
	 * @return
	 */
	public static String getSid(final String contextRoot, final String href) {
		String result = href.substring(href.indexOf(contextRoot) + contextRoot.length());
		return result;
	}
	
	/**
	 * 전달된 매개변수로 부터 접근권한대상ID를 추출하여 반환
	 * @param request
	 * @return
	 */
	public static String getSid(final HttpServletRequest request) {
		final String contextRoot = request.getContextPath() + "/";
		final String uri = request.getRequestURI();
		final String query = request.getQueryString();
		
		logger.debug("contextRoot:" + contextRoot + ",uri:" + uri + ",query:" + query);

		return getSid(contextRoot, uri, query);
	}
}
